#include <iostream>
#include <stdio.h>
#include <fstream>
#include <stdlib.h>
#include <string>
using namespace std;

int main(int argc, char** argv)
{
    char filename[1024];
    string line;
    int i, j, m;
    double srho, nrho, rho, ratio, sumratio;
    ifstream nfile, sfile;
    double max = 0.0, min = 1000000000.0;

    if (argc < 3)
    {
	cout << "Usage: maketimes prefix maxk" << endl;
	return 0;
    }

    for(i = 2; i < atoi(argv[2]); ++i)
    {
	sprintf(filename, "%sNAIVE-DENSITY.txt", argv[1]);
	nfile.open(filename);
	sprintf(filename, "%s%dBINS-DENSITY.txt", argv[1], i);
        sfile.open(filename);

	sumratio = 0.0; m = 0;
	max = 0.0, min = 1000000000.0;
	if (nfile.is_open() && sfile.is_open())
	{
	    while (getline(nfile, line))
	    {
		sscanf(line.c_str(), "%lf", &nrho);
		getline(sfile, line);
		sscanf(line.c_str(), "%lf", &srho);

		ratio = nrho/srho;
		if (ratio > max)
		{
		    max = ratio;
		    //cout << m << ": " << nrho << " " << srho << endl;
		}

		if (ratio < min)
		{
		    min = ratio;
		}		 
   
		sumratio += ratio;
		m++;
	    }
	    sfile.close();
	    nfile.close();
	    cout << argv[1] << " " << i << " bins  & " << max << " & " << sumratio/m << endl;
	}
    }
    
    return 0;
}
